﻿using Sumen.Business;
using Sumen.Library.UserControl.DanhMuc;

using DevExpress.XtraSplashScreen;

using Sumen.Business.Permission;
using Sumen.Business.Presenter.Sys;
using Sumen.Library.Enum;
using Sumen.Library.Froms;



namespace Sumen.GUI.Category
{
    public partial class Frm_Customer_Type : XtraUserControlKira
    {
        private EnumFormCode _fromCode = EnumFormCode.FrmCustomerType;
        public Frm_Customer_Type()
        {
            InitializeComponent();
            ucDanhMuc1.btnArray.capQuyen(new Permission(_fromCode.ToString(), ClsPublic.User.User_Username));
            ucDanhMuc1.mySetValidate = new UCDanhMuc.setValidate(myValidate);
            //if (ClsPublic.SYSTEM_WRITELOG == "1")
            //{
            //    SysLogPresenter log = new SysLogPresenter();
            //    log.Add(_fromCode, EnumFormStatus.View, "", "");
            //}
            this.Disposed += Frm_Customer_Type_Disposed;
        }

        void Frm_Customer_Type_Disposed(object sender, System.EventArgs e)
        {
            ClsPublic.WriteLog(_fromCode, EnumFormStatus.Modify, "", "");
        }

        private void myValidate(DevExpress.XtraGrid.Views.Grid.GridView g, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {

                e.Valid = ucDanhMuc1.Check_NULL(g, "CusT_Name", "Không được rỗng");
                if (!e.Valid) return;
                e.Valid = ucDanhMuc1.Check_MA(g, "", "CusT_Code");
                if (!e.Valid) return;
                e.Valid = ucDanhMuc1.Check_Length(g, "CusT_Code", 2, 2);
                if (!e.Valid) return;
                e.Valid = ucDanhMuc1.Check_NULL(g, "CusT_PriceTypeId", "Không được rỗng");
                if (!e.Valid) return;
            }
            catch
            {

            }
        }

        public override void Refresh()
        {
            base.Refresh();
            ucDanhMuc1.reLoad();
            ucDanhMuc1.reLoadParent();
        }



    }
}